package com.taxshare.operation.controller;

import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.response.beans.Response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.taxshare.operation.service.InterfaceService;
import com.taxshare.operation.view.vo.ApiInfoVO;
import com.taxshare.operation.view.vo.ApiQyztReqVO;

@RestController
@RequestMapping(value = "/api")
@Api(tags = "【接口维护】-api")
public class InterfaceController {

	@Autowired
    private InterfaceService interfaceService;

    /**
     * 接口信息录入
     */
    @ApiOperation(value = "接口信息录入", notes = "接口信息录入")
    @PostMapping("/save")
    public Response saveApi(@RequestBody ApiInfoVO reqVO) {
        return interfaceService.saveApi(reqVO);
    }

    /**
     * 接口信息列表展示-分页
     */
    @ApiOperation(value = "接口信息列表分页", notes = "接口信息列表分页")
    @PostMapping("/show/list")
    public Response<IPage<ApiInfoVO>> queryPageList(@RequestBody PageRequest<ApiInfoVO> apiInfoVO) {
        return interfaceService.queryPageList(apiInfoVO);
    }
    
    @RequestMapping(method = RequestMethod.POST, value = "/info/queryList")
    @ApiOperation(notes = "接口信息列表", value = "接口信息列表")
    public Response<List<ApiInfoVO>> queryList(@RequestBody ApiInfoVO apiInfoVO) {
        return interfaceService.queryList(apiInfoVO);
    }

    /**
     * 预览接口信息
     */
    @ApiOperation(value = "预览接口信息", notes = "预览接口信息")
    @PostMapping("/show/info")
    public Response showApiInfo(@RequestParam String uuid) {
        return interfaceService.showApiInfo(uuid);
    }

    /**
     * 更新接口信息
     */
    @ApiOperation(value = "更新接口信息", notes = "更新接口信息")
    @PostMapping("/update/info")
    public Response udpateApiInfo(@RequestBody ApiInfoVO reqVO) {
        return interfaceService.udpateApiInfo(reqVO);
    }

    /**
     * 更新接口排序字段
     */
    @ApiOperation(value = "更新接口排序字段", notes = "更新接口排序字段")
    @PostMapping("/update/sort")
    public Response updateApiSort(@RequestBody ApiQyztReqVO apiQyztReqVO) {
        return interfaceService.updateApiSort(apiQyztReqVO);
    }

    /**
     * 删除接口信息
     */
    @ApiOperation(value = "删除接口信息", notes = "删除接口信息")
    @PostMapping("/delete/info")
    public Response deleteApiInfo(@RequestParam String uuid) {
        return interfaceService.deleteApiInfo(uuid);
    }

    /**
     * 更新接口的启用状态
     */
    @ApiOperation(value = "更新接口的启用状态", notes = "更新接口的启用状态")
    @PostMapping("/update/status")
    public Response updateApiQyzt(@RequestBody ApiQyztReqVO apiQyztReqVO) {
        return interfaceService.updateApiSort(apiQyztReqVO);
    }

    @PostMapping(value = "/info/uploadOri")
    @ApiOperation(notes = "文件管理", value = "文件上传")
    public Response uploadOri(@RequestParam("files") MultipartFile files,@RequestParam String uuid){
    	return interfaceService.uploadFile(files,uuid);
    }
    
    @GetMapping(value = "/info/down")
    @ApiOperation(notes = "文件管理", value = "下载文件")
    public void down(HttpServletResponse response,@RequestParam String uuid){
    	interfaceService.down(response, uuid);
    }
}
